﻿using System.Web.SessionState;
using NUnit.Framework;
using ProjetoComperio.BusinessLogicLayer;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.Presentation.Web.Controllers;
using System.Web.Mvc;
using System.Linq;
using System;
using ProjetoComperio.Test.FakeData;
using ProjetoComperio.Test.WebUI.FakeObjects;

namespace ProjetoComperio.Test.WebUI.Controllers
{
    [TestFixture]
    public class EducationalITApplicationControllerTest
    {
        FormCollection formCollection;
        private EducationalITApplicationController educationalITApplicationController;
        private EducationalITApplicationBLL educationalITApplicationBLL;

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            formCollection = new FormCollection();
            educationalITApplicationBLL = new EducationalITApplicationBLL();
            educationalITApplicationController = new EducationalITApplicationController(educationalITApplicationBLL);
        }

        [SetUp]
        public void SetUp()
        {
            educationalITApplicationBLL.InitializeDataContext(new FakeComperioEntitiesDataModel());
            SessionStateItemCollection sessionStateItemCollection = new SessionStateItemCollection();
            educationalITApplicationController.ControllerContext = new FakeControllerContext(educationalITApplicationController, sessionStateItemCollection, CommonData.UserName);
        }


        [Test]
        public void TestCreateValidEntityOpenSourceAndFree()
        {
            var educationalITApplication = FillValidEducationalITApplication();
            educationalITApplicationController.Create(educationalITApplication);

            Assert.IsTrue(educationalITApplicationBLL.RetrieveEducationalITApplications().Any(x => x.Title.Equals(educationalITApplication.Title)));
        }

        private EducationalITApplication FillValidEducationalITApplication()
        {
            var educationalITApplication = new EducationalITApplication();

            educationalITApplication.Title = "prjTeste" + DateTime.Now;
            educationalITApplication.UseInstructions = "intrução de uso";
            educationalITApplication.IsOpenSource = true;
            educationalITApplication.IsFree = true;
            educationalITApplication.AdditionalInfo = "Fonte";
            educationalITApplication.AdditionalInfo = "Info";

            return educationalITApplication;
        }

        [Ignore("Don't make any sense test update 'cause we are mocking the Database")]
        public void TestEditValieEntity()
        {


        }


    }
}
